package com.summerxia.dateselector.widget;

import android.content.Context;
import android.util.AttributeSet;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;

import com.summerxia.dateselector.R;
import com.summerxia.dateselector.wheelview.NewsClassifyAdapter;
import com.summerxia.dateselector.wheelview.NewsCompontentsAdapter;
import com.summerxia.dateselector.wheelview.OnWheelChangedListener;
import com.summerxia.dateselector.wheelview.WheelView;

import java.util.List;

/**
  * 类描述:	地址选择器的自定义布局   
  * 项目名称:  DateSelector   
  * 类名称:   AreasWheel 
  * 创建人:    xhl  
  * 创建时间:  2015-2-5 上午10:11:53     
  * 版本:      v1.0
 */
public class NewsCompontentWheel extends LinearLayout {
	private WheelView news_compontent;
	private WheelView news_classify;
	private Context context;
	private NewsClassifyAdapter classifyAdapter;
	private NewsCompontentsAdapter compontentsAdapter;
	private Boolean isOnlyClassify = false;


	public NewsCompontentWheel(Context context, AttributeSet attrs, int defStyleAttr) {
		super(context, attrs, defStyleAttr);
		this.context = context;
		initView();
	}

	public NewsCompontentWheel(Context context, AttributeSet attrs) {
		super(context, attrs);
		this.context = context;
		initView();
	}

	public NewsCompontentWheel(Context context) {
		super(context);
		this.context = context;
		initView();
	}

	private void initView() {
		LayoutInflater.from(context).inflate(
				R.layout.compontent_classfiy_selector_layout, this, true);
		news_compontent = (WheelView) findViewById(R.id.compontent_name);
		news_classify = (WheelView) findViewById(R.id.classfiy_name);

		compontentsAdapter = new NewsCompontentsAdapter(context);
		news_compontent.setAdapter(compontentsAdapter);
		news_compontent.setCyclic(false);
		news_compontent.setVisibleItems(5);
		news_compontent.setCurrentItem(0);


		classifyAdapter = new NewsClassifyAdapter(context);
		news_classify.setAdapter(classifyAdapter);
		news_classify.setCyclic(false);
		news_classify.setVisibleItems(5);
	}

	public WheelView getNews_compontent() {
		return news_compontent;
	}

	/**
	 * 获取组件名称
	 * 
	 * @return
	 */
	public String getNewsName() {
		if(isOnlyClassify){
			return news_classify.getCurrentItemValue();
		}
		return news_compontent.getCurrentItemValue() + "_"
				+ news_classify.getCurrentItemValue();
	}
	/**
	 * 获取组件的ID
	 * @return
	 */
	public String getCompontentId(){
		return news_compontent.getCurrentItemId();
	}
	/**
	 * 获取分类的Id
	 * @return
	 */
	public String getClassifyId(){
		return news_classify.getCurrentItemId();
	}

	public void setNewsCompontents(List<String> newsCompontents) {
		compontentsAdapter.setNewsCompontents(newsCompontents);
	}

	public void setClassifys(List<String> classifys,int num) {
		classifyAdapter.setClassifys(classifys);
		Log.e("setClassifys","num:" + num);
		news_classify.setAdapter(classifyAdapter);
		news_classify.setCurrentItem(num);
	}

	public void setOnlyClassify(){
		isOnlyClassify = true;
		news_compontent.setVisibility(View.GONE);
	}


}
